package org.i1510.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.i1510.common.bean.SessionUserBean;
import org.i1510.common.utils.KBProperties;
import org.i1510.common.utils.UserUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @author rambo
 * 拦截器基类 增加allowUrls属性
 */
public class BaseInterceptor extends HandlerInterceptorAdapter {
	private static Logger logger = LoggerFactory
			.getLogger(BaseInterceptor.class);

	public String[] allowUrls;// spring3.2以前的版本不支持mvc:exclude 配置不拦截的资源，在代码里面增强该方法，目前不支持通配符和正则

	public void setAllowUrls(String[] allowUrls) {
		this.allowUrls = allowUrls;
	}

	public boolean isAllow(HttpServletRequest request) {

		String requestUri = request.getRequestURI();
		// String contextPath = request.getContextPath();
		String requestUrl = requestUri.replace(request.getContextPath(), "");
		// 如果有设置不过滤的URL则直接跳过
		if (null != allowUrls && allowUrls.length >= 1) {
			for (String url : allowUrls) {
				if (requestUrl.contains(url)) {
					return true;
				}
			}
		}
		return false;
	}
	

}